package com.fyzk.activity.lottery.zc;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tyjc.lottery.R;

import java.util.ArrayList;
import java.util.List;


public class ZCFX_view extends LinearLayout{
	
	private List<List<Object>> list = new ArrayList<List<Object>>();
	private int type;
	
	private Context context;
	
	private MyExpandableListView listView;
	private ZCFX_ExpAdapter adapter;
	
	
	
	private String[] titles_ss = {"比赛事件","技术统计"};
	private String[] titles_zr = {"阵型","首发阵容","替补阵容","主教练"};
	private String[] titles_fx = {"历史交锋","近期战绩","积分排名","未来三场"};
	private String[] titles_pl = {"欧赔","亚赔"};
	private String[] titles = new String[]{};
	
	public ZCFX_view(Context context,int type){
		this(context, null, type);
	}

	public ZCFX_view(Context context, AttributeSet attrs,int type) {
		super(context, attrs);
		this.context = context;
		this.type = type;
		
		switch (type) {
		case 0:
			titles = titles_ss;
			break;
		case 1:
			titles = titles_zr;
			break;
		case 2:
			titles = titles_fx;
			break;
		case 3:
			titles = titles_pl;
			break;
		default:
			break;
		}
		
		View view = LayoutInflater.from(context).inflate(R.layout.zcfx_vp, null);
//		wuJiLu = (LinearLayout)view.findViewById(R.id.zcfx_vp_wujilu);
		listView = (MyExpandableListView)view.findViewById(R.id.zcfx_vp_explist);
		adapter = new ZCFX_ExpAdapter();
		listView.setAdapter(adapter);
		listView.setGroupIndicator(null);
		
		
		this.addView(view);
	}
	
	private void notifyChanged(){
		adapter.notifyDataSetChanged();
	}

	
	/**
	 * expandableListView   适配器
	 */
	class ZCFX_ExpAdapter extends BaseExpandableListAdapter{

		@Override
		public Object getChild(int groupPosition, int childPosition) {

			return list.get(groupPosition).get(childPosition);
		}

		@Override
		public long getChildId(int groupPosition, int childPosition) {

			return childPosition;
		}

		
		int index_c;
		@Override
		public View getChildView(int groupPosition, int childPosition,
				boolean isLastChild, View convertView, ViewGroup parent) {
			View view = null;
			view = LayoutInflater.from(context).inflate(R.layout.zcfx_explist_fx1, null);//替换
			index_c = childPosition;
			ZCFX_fx_lsjf lsjf = (ZCFX_fx_lsjf) list.get(groupPosition).get(index_c);
			
			TextView tv1 = (TextView)view.findViewById(R.id.zcfx_explist_fx1_tv1);
			TextView tv2 = (TextView)view.findViewById(R.id.zcfx_explist_fx1_tv2);
			TextView tv3 = (TextView)view.findViewById(R.id.zcfx_explist_fx1_tv3);
			TextView tv4 = (TextView)view.findViewById(R.id.zcfx_explist_fx1_tv4);
			TextView tv5 = (TextView)view.findViewById(R.id.zcfx_explist_fx1_tv5);
			TextView tv6 = (TextView)view.findViewById(R.id.zcfx_explist_fx1_tv6);
			TextView tv7 = (TextView)view.findViewById(R.id.zcfx_explist_fx1_tv7);
			TextView tv8 = (TextView)view.findViewById(R.id.zcfx_explist_fx1_tv8);
			TextView tv9 = (TextView)view.findViewById(R.id.zcfx_explist_fx1_tv9);
			TextView tv10 = (TextView)view.findViewById(R.id.zcfx_explist_fx1_tv10);
			
			
			switch (groupPosition) {
			case 0://历史交锋
				tv7.setVisibility(View.GONE);
				tv8.setVisibility(View.GONE);
				tv9.setVisibility(View.GONE);
				tv10.setVisibility(View.GONE);
				if (lsjf.getId() == 1) {
					
				}else if(lsjf.getId() == 3){
					tv1.setText(lsjf.getSaishi());
					tv2.setText(lsjf.getTime());
					tv3.setText(lsjf.getZhu());
					tv4.setText(lsjf.getBifen());
					tv5.setText(lsjf.getKedui());
					tv6.setText(lsjf.getBanchang());
					
					tv4.setTextColor(Color.RED);
					tv6.setTextColor(Color.RED);
				}
				break;
			case 1://近期战绩
				tv7.setVisibility(View.GONE);
				tv8.setVisibility(View.GONE);
				tv9.setVisibility(View.GONE);
				tv10.setVisibility(View.GONE);
				if (lsjf.getId() == 1) {
					
					tv6.setText("胜负");
				}else if (lsjf.getId() == 2) {
					if (childPosition == 0) {
						
						tv1.setText(lsjf.getZhu());
					}else{
						tv1.setText(lsjf.getKedui());
					}
					tv1.setGravity(Gravity.LEFT);
					
					
					tv2.setVisibility(View.GONE);
					tv3.setVisibility(View.GONE);
					tv4.setVisibility(View.GONE);
					tv5.setVisibility(View.GONE);
					tv6.setVisibility(View.GONE);
				}else if(lsjf.getId() == 0){
					tv2.setVisibility(View.GONE);
					tv3.setVisibility(View.GONE);
					tv4.setVisibility(View.GONE);
					tv5.setVisibility(View.GONE);
					tv6.setVisibility(View.GONE);
					tv7.setVisibility(View.GONE);
					tv8.setVisibility(View.GONE);
					tv9.setVisibility(View.GONE);
					tv10.setVisibility(View.VISIBLE);
					
					tv1.setText("共 "+(childPosition - 5)+" 场"+"胜 3 "+"平 0 "+"负 3 ");
					tv10.setText("胜率：50%");
					
					tv1.setGravity(Gravity.RIGHT);
					tv10.setGravity(Gravity.LEFT);
					tv10.setTextColor(Color.RED);
					
				}else{
					tv1.setText(lsjf.getSaishi());
					tv2.setText(lsjf.getTime());
					tv3.setText(lsjf.getZhu());
					tv4.setText(lsjf.getBifen());
					tv5.setText(lsjf.getKedui());
					
					tv4.setTextColor(Color.RED);
					if(childPosition % 2 == 0){
						tv6.setText("负");
						tv6.setTextColor(Color.GREEN);
					}else{
						
						tv6.setText("胜");
						tv6.setTextColor(Color.RED);
					}
					
				}
				
				break;
			case 2://积分排名
				if (lsjf.getId() == 1) {
					tv1.setText("类型");
					tv2.setText("排名");
					tv3.setText("赛");
					tv4.setText("胜");
					tv5.setText("平");
					tv6.setText("负");
				}else if (lsjf.getId() == 2) {
					if (childPosition == 0) {
						
						tv1.setText(lsjf.getZhu());
					}else{
						tv1.setText(lsjf.getKedui());
					}
					tv1.setGravity(Gravity.LEFT);
					
					tv2.setVisibility(View.GONE);
					tv3.setVisibility(View.GONE);
					tv4.setVisibility(View.GONE);
					tv5.setVisibility(View.GONE);
					tv6.setVisibility(View.GONE);
					tv7.setVisibility(View.GONE);
					tv8.setVisibility(View.GONE);
					tv9.setVisibility(View.GONE);
					tv10.setVisibility(View.GONE);
				}else{
					tv1.setText("全部");
					tv2.setText("12");
					tv3.setText("34");
					tv4.setText("14");
					tv5.setText("11");
					tv6.setText("12");
					tv7.setText("34");
					tv8.setText("14");
					tv9.setText("11");
					tv10.setText("12");
					
					tv4.setTextColor(Color.RED);
					if(childPosition % 2 == 0){
						tv6.setText("负");
						tv6.setTextColor(Color.GREEN);
					}else{
						
						tv6.setText("胜");
						tv6.setTextColor(Color.RED);
					}
					
				}
				break;
			case 3:
				tv4.setVisibility(View.GONE);
				tv6.setVisibility(View.GONE);
				tv7.setVisibility(View.GONE);
				tv8.setVisibility(View.GONE);
				tv9.setVisibility(View.GONE);
				tv10.setVisibility(View.GONE);
				if (lsjf.getId() == 1) {
					
				}else if (lsjf.getId() == 2) {
					if (childPosition == 0) {
						
						tv1.setText(lsjf.getZhu());
					}else{
						tv1.setText(lsjf.getKedui());
					}
					tv1.setGravity(Gravity.LEFT);
					
					tv2.setVisibility(View.GONE);
					tv3.setVisibility(View.GONE);
				}else{
					tv1.setText(lsjf.getSaishi());
					tv2.setText(lsjf.getTime());
					tv3.setText(lsjf.getZhu());
					tv5.setText(lsjf.getKedui());
					
				}
				break;
			default:
				break;
			}
			
			return view;
		}

		@Override
		public int getChildrenCount(int groupPosition) {

			return list.get(groupPosition).size();
		}

		@Override
		public Object getGroup(int groupPosition) {

			return list.get(groupPosition);
		}

		@Override
		public int getGroupCount() {

			return list.size();
		}

		@Override
		public long getGroupId(int groupPosition) {

			return groupPosition;
		}

		@Override
		public View getGroupView(int groupPosition, boolean isExpanded,
				View convertView, ViewGroup parent) {

			View view = LayoutInflater.from(context).inflate(R.layout.zcfx_explist_group, null);
			TextView tv = (TextView)view.findViewById(R.id.zcfx_explist_group_tv);
			TextView tv2 = (TextView)view.findViewById(R.id.zcfx_explist_group_tv2);
			
			
			tv.setText(titles[groupPosition]);
			
			if (list.get(groupPosition).size() == 0) {
				tv2.setVisibility(View.VISIBLE);
			}else{
				tv2.setVisibility(View.GONE);
			}
			
			return view;
		}

		@Override
		public boolean hasStableIds() {

			return false;
		}

		@Override
		public boolean isChildSelectable(int groupPosition, int childPosition) {

			return true;
		}
		
	}
	
	
	
	
	
	
	public List<List<Object>> getList() {
		return list;
	}

	public void setList(List<List<Object>> list) {
		this.list = list;
		
		notifyChanged();
	}
	
	
	
	
	
}
